package com.xca.rxjavademo.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.xca.rxjavademo.R;
import com.xca.rxjavademo.entity.Weather;
import com.xca.rxjavademo.utils.WeatherBackgroundUtils;

import java.util.List;

public class WeatherDayAdapter extends RecyclerView.Adapter<WeatherDayAdapter.ViewHolder>{
    private List<Weather.Result.HourlyForecast> mList ;
    private Context mContext ;
    private Activity activity ;

    public WeatherDayAdapter(List<Weather.Result.HourlyForecast> list , Context context , Activity activity){
        this.mList = list ;
        this.mContext = context ;
        this.activity = activity ;
    }
    public void updateData(List<Weather.Result.HourlyForecast> list){
        mList.clear();
        mList = list ;
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_weather_today , parent , false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Weather.Result.HourlyForecast hourlyForecast = mList.get(position);
        holder.tv1.setText(hourlyForecast.getCondition());
        holder.tv2.setText(hourlyForecast.getTemperature());
        String wind_direction = WeatherBackgroundUtils.getDirection(hourlyForecast.getWind_direction());
        holder.tv3.setText(wind_direction);
        holder.tv4.setText(hourlyForecast.getWind_level());
        holder.tv5.setText(hourlyForecast.getHour());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv1 , tv2 , tv3 , tv4 , tv5 ;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv1 = itemView.findViewById(R.id.wt_weather);
            tv2 = itemView.findViewById(R.id.wt_temperature);
            tv3 = itemView.findViewById(R.id.wt_wind);
            tv4 = itemView.findViewById(R.id.wt_wind_power);
            tv5 = itemView.findViewById(R.id.wt_time);
        }
    }
}
